package cn.szzsi.business.controller.admin;

import cn.szzsi.AConfig;
import cn.szzsi.business.service.BrandStoreService;
import cn.szzsi.common.bean.dto.Msg;
import cn.szzsi.common.excel.ExcelReader;
import cn.szzsi.common.excel.PoiRender;
import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.common.util.SerialNumberUtil;
import cn.szzsi.model.BrandStore;
import cn.szzsi.model.BrandStoreCategory;
import cn.szzsi.model.Member;
import com.jfinal.aop.Before;
import com.jfinal.core.JFinal;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.render.Render;
import com.jfinal.upload.UploadFile;
import org.apache.commons.collections.map.HashedMap;
import org.json.JSONObject;

import java.io.*;
import java.net.URLEncoder;
import java.util.*;

/**
 * 品牌门店
 * Created by zhengy on 2017/3/21.
 */
public class BrandStoreController extends BaseAdminController<BrandStore> {
    private BrandStore brandStore;
    private String shopId;
    public void list(){
        /*String path="https://" + getRequest().getServerName() + getRequest().getContextPath() + getRequest().getServletPath() + "?" + getRequest().getQueryString();
        System.out.println(getRequest().getServerName());
        System.out.println(getRequest().getContextPath());
        System.out.println(getRequest().getServletPath());
        System.out.println(getRequest().getRequestURL());
        System.out.println(getRequest().getRequestURI());*/
        String pageType=getPara("pageType");
        if("add".equals(pageType)){
            redirect("add");
            return;
        }
        String type=getPara("type","0");
        setAttr("qrurl","https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=");
        if("0".equals(type)){
            render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/brand_store_list.html");
        }else{
            render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/brand_section_list.html");
        }

    }
    public void ajaxlist(){
        shopId=getAttr("shopId");
        String type=getPara("type","0");
        String sql="select b.*,c.name storeCategoryName from sys_brand_store b left join sys_brand_store_category c on b.storeCategoryId=c.id where 1=1";
        if("0".equals(type)){//门店
            sql +=" and b.type='0'";
        }else if("1".equals(type)){//部门
            sql +=" and b.type='1'";
        }

        String province=getPara("province");
        if(StrKit.notBlank(province)&& !"全部".equals(province)){
            sql +=" and b.province='"+province+"'";
        }
        String city=getPara("city");
        if(StrKit.notBlank(city)&&!"全部".equals(city)){
            sql +=" and b.city='"+city+"'";
        }
        String district=getPara("district");
        if(StrKit.notBlank(district)&&!"全部".equals(district)&&!"市辖区".equals(district)){
            sql +=" and b.district='"+district+"'";
        }
        String name=getPara("name");
        if(StrKit.notBlank(name)){
            sql +=" and (b.business_name like '%"+name+"%' or b.branch_name like'%"+name+"%')";
        }
        sql+=" and b.shopId='"+shopId+"' order by b.storeStatus desc,b.createDate desc";
        List<BrandStore> lbs = BrandStore.dao.find(sql);
        for(BrandStore bs:lbs){
            bs.init();
        }
        renderJson(lbs);
    }

    public void add(){
        //createToken("jockillerToken", 30*60);
        shopId=getAttr("shopId");
        String type=getPara("type","0");
        if("0".equals(type)){
            setAttr("allStoreCategoryList",BrandStoreCategory.dao.getByShopId(shopId));
            render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/brand_store_add.html");
        }else{
            render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/brand_section_input.html");
        }
    }
    //@Before(BrandStoreValidator.class)
    public void save(){
        shopId=getAttr("shopId");
        brandStore = getModel(BrandStore.class);
        String regex="^[a-zA-Z0-9]+$";
        if(StrKit.notBlank(brandStore.getStoreNum())){
            if(!brandStore.getStoreNum().matches(regex)){
                renderJson(Ret.fail("info","门店编号只能输入字母或者数字"));
                return;
            }

        }

        if(StrKit.isBlank(brandStore.getStoreNum())){
            String  storeNum=SerialNumberUtil.buildStoreNum();
            brandStore.set("storeNum",storeNum);
        }
        if(BrandStore.dao.getByStoreNumAndShopId(brandStore.getStoreNum(),shopId)!=null){
            renderJson(Ret.fail("info","门店编号已存在!"));
            return;
        }
        if("请选择".equals(brandStore.getProvince())){
            renderJson(Ret.fail("info","请选择省市区!"));
            return;
        }
        String category_one=getPara("category_one");
        String category_two=getPara("category_two");
        brandStore.set("shopId",shopId);
        brandStore.set("mapType",getPara("map_type"));
        brandStore.set("categories",category_one+","+category_two);
        saved(brandStore);
        renderJson(Ret.ok("info","添加成功!").set("url","list?type="+brandStore.getInt("type")));
    }
    public void edit(){
        shopId=getAttr("shopId");
        String id = getPara("id","");
        String type=getPara("type","0");
        if(StrKit.notBlank(id)){
            brandStore=BrandStore.dao.findById(id);
            setAttr("brandStore", BrandStore.dao.findById(id));
            String categories=brandStore.getStr("categories");
            if(StrKit.notBlank(categories)){
                String arr[]=categories.split(",");
                setAttr("category_one",arr[0]);
                setAttr("category_two",arr[1]);
            }

        }
        if("0".equals(type)){
            setAttr("allStoreCategoryList",BrandStoreCategory.dao.getByShopId(shopId));
            render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/brand_store_input.html");
        }else{
            render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/brand_section_input.html");
        }
    }
    public void update(){
        shopId=getAttr("shopId");
        brandStore = getModel(BrandStore.class);
        String regex="^[a-zA-Z0-9]+$";
        String brandStoreNum=brandStore.getStoreNum();
        if(StrKit.notBlank(brandStoreNum)&&!brandStoreNum.matches(regex)){
            renderJson(Ret.fail("info","门店编号只能输入字母或者数字"));
            return;
        }
        if(StrKit.isBlank(brandStore.getStoreNum())){
            String  storeNum=SerialNumberUtil.buildStoreNum();
            brandStore.set("storeNum",storeNum);
        }
        if(BrandStore.dao.getByStoreNumAndShopIdAndId(brandStore.getStoreNum(),shopId,brandStore.getId())!=null){
            renderJson(Ret.fail("info","门店编号已存在!"));
            return;
        }
        String category_one=getPara("category_one");
        String category_two=getPara("category_two");
        brandStore.set("mapType",getPara("map_type"));
        brandStore.set("categories",category_one+","+category_two);
        updated(brandStore);

        System.out.println(brandStore.getStr("id"));
        brandStore=BrandStore.dao.findById(brandStore.getStr("id"));
        System.out.println(brandStore.getStr("poiId"));
        if(brandStore.getInt("type")==0 && brandStore.getInt("status")==2){//门店,并且审核通过
            Map<String,Object>business=new HashMap();
            Map<String,Object>base_info=new HashMap();
            Map<String,Object> map=new HashMap();
            String recommend=brandStore.getStr("recommend");//推荐
            String special=brandStore.getStr("special");//特色服务
            String introduction=brandStore.getStr("introduction");//商户简介
            String open_time=brandStore.getStr("open_time");//开放时间
            String avg_price=brandStore.getStr("avg_price");//人均价格
            map.put("poi_id",brandStore.getStr("poiId"));//门店id
            map.put("telephone",brandStore.getStr("telephone"));
            if(StrKit.notBlank(recommend)){
                map.put("recommend",recommend);
            }
            if(StrKit.notBlank(special)){
                map.put("special",special);
            }
            if(StrKit.notBlank(introduction)){
                map.put("introduction",introduction);
            }
            if(StrKit.notBlank(open_time)){
                map.put("open_time",open_time);
            }
            if(StrKit.notBlank(avg_price)){
                map.put("avg_price",avg_price);
            }
            base_info.put("base_info",map);
            business.put("business",base_info);
            String access_token=CommonUtil.getAccessToken(shopId);
            String reqUrl="https://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token="+access_token;
            String result= HttpKit.post(reqUrl,JsonKit.toJson(business));
            JSONObject jo=new JSONObject(result);
            String errmsg=jo.getString("errmsg");
            if(!"ok".equals(errmsg)){
                renderJson(Ret.fail("info","推送失败!"));
            }
        }
        renderJson(Ret.ok("info","修改成功!").set("url","list?type="+brandStore.getInt("type")));
    }

    /**
     * 门店二维码
     */
    public void qrcode(){
        shopId=getAttr("shopId");
        String id=getPara("id");
        BrandStore bs=BrandStore.dao.findById(id);
        if(bs.getStr("ticket")!=null){//二维码存在
            redirect("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+bs.getTicket());
        }else{//二维码不存在
            //1.创建门店二维码
            String scene_id = "store@"+id;//场景id
            String access_token=CommonUtil.getAccessToken(shopId);
            if(StrKit.notBlank(access_token)){
                String str = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\":\"" + scene_id + "\"}}}";//字符串形式的二维码参数
                String result=HttpKit.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+access_token,str);
                JSONObject joo=new JSONObject(result);
                String ticket=joo.getString("ticket");//获取的二维码ticket，凭借此ticket可以在有效时间内换取二维码。
                String qrcodeUrl=joo.getString("url");//二维码图片解析后的地址，开发者可根据该地址自行生成需要的二维码图片
                bs.set("scene_id",scene_id);
                bs.set("ticket",ticket);
                bs.set("qrcodeUrl",qrcodeUrl).update();
                redirect("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ticket);
            }else{
                renderJson(Ret.fail("info","创建失败!"));

            }
        }

    }

    /**
     * 对于审核通过的门店,如果删除,则微信公众号上的额也要删除
     */
    public void delete(){
        shopId=getAttr("shopId");
        ids = getParaValues("ids");
        for(String id:ids){
            BrandStore bs=BrandStore.dao.findById(id);
            if(bs.getInt("status")==1){
                renderJson(Ret.fail("info","该门店在审核中,无法删除!"));
                return;
            }else if(bs.getInt("status")==2 || bs.getInt("status")==3){
                bs.delete();
                //对于审核通过和审核不通过的门店,如果删除,则微信公众号上的额也要删除
                String poi_id=bs.getStr("poiId");
                String access_token=CommonUtil.getAccessToken(shopId);
                String deleteUrl="https://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token="+access_token;
                HashMap map=new HashMap();
                map.put("poi_id",poi_id);
                HttpKit.post(deleteUrl,JsonKit.toJson(map));
            }
            bs.delete();
        }
        renderJson(Ret.ok("info","删除成功!"));
    }

    /**
     * 查看审核不通过原因
     */
    public void reasonDetail(){
        String id = getPara("id","");
        brandStore=BrandStore.dao.findById(id);
        setAttr("brandStore",brandStore);
        render(CommonUtil.TEMPLATE_PATH+"/business/brandstore/reson_detail.html");
    }

    /**
     * 批量导出门店
     */
    public void exportStore(){
        shopId=getAttr("shopId");
        String sql="select b.storeNum,b.business_name,b.branch_name,CONCAT(b.province,b.city,b.district,b.address) address,b.latitude,b.longitude,(case when b.status=0 then '未推送' when b.status=1 then '审核中' when b.status=2 then '审核通过' else '审核不通过' end)status,b.telephone,b.categories,IFNULL(b.recommend,\"\")recommend,IFNULL(b.special,\"\")special,IFNULL(b.introduction,\"\")introduction,IFNULL(b.open_time,\"\")open_time,IFNULL(b.avg_price,\"\")avg_price from sys_brand_store b where b.shopId=? and b.type=0";
        String province=getPara("province");
        if(StrKit.notBlank(province)&& !"全部".equals(province)){
            sql +=" and b.province='"+province+"'";
        }
        String city=getPara("city");
        if(StrKit.notBlank(city)&&!"全部".equals(city)){
            sql +=" and b.city='"+city+"'";
        }
        String district=getPara("district");
        if(StrKit.notBlank(district)&&!"全部".equals(district)&&!"市辖区".equals(district)){
            sql +=" and b.district='"+district+"'";
        }
        String name=getPara("name");
        if(StrKit.notBlank(name)){
            sql +=" and (b.business_name like '%"+name+"%'";
        }
        List<Record>list=Db.find(sql,shopId);
        String[] header={"门店编号","门店名称","门店地址","经度","维度","审核状态","电话","服务类型","推荐","特色服务","商户简介","营业时间","人均价格"};
        String[] columns={"storeNum","business_name","address","latitude","longitude","status","telephone","categories","recommend","special","introduction","open_time","avg_price"};
        Render poirender = PoiRender.me(list).fileName("store.xls").headers(header).sheetName("store").columns(columns);
        render(poirender);
    }

    /**
     * 门店导入示例
     */
    public void importStoreDemo(){
        List list=new ArrayList();
        Map<String,Object>map=new HashedMap();
        map.put("storeNum","25987");
        map.put("business_name","欧尚超市");
        map.put("province","江苏省");
        map.put("city","苏州市");
        map.put("district","吴中区");
        map.put("address","星塘街欧尚超市");
        map.put("longitude",120.74637);
        map.put("latitude",31.29846);
        map.put("status",0);
        map.put("telephone","18006217166");
        map.put("categories","购物,超市");
        map.put("recommend","苹果,蔬菜");
        map.put("special","免费wifi");
        map.put("introduction","便民服务");
        map.put("open_time","8:00-21:00");
        map.put("avg_price","35.9");
        map.put("storeCategoryId","星级门店");
        list.add(map);
        //list.add("{business_name=微米荟商城, branch_name=星湖街店, province=江苏省, city=苏州市, district=吴中区, address=星湖街238号, longitude=120.73648, latitude=31.29612, status=0, telephone=18006217166, categories=生活服务,旅行社}");
        String[] header={"门店编号(选填)","门店名称(必填)","门店所在省(必填)","门店所在市(必填)","门店所在区(必填)","详细地址(必填)","经度(选填)","维度(选填)","电话(必填)","服务类型(一级类目和二级类目之间用逗号隔开,选填)","推荐品(餐厅可为推荐菜,选填)","特色服务(如免费wifi，免费停车,选填)","商户简介(选填)","营业时间","人均价格(大于0的整数,选填)","门店类别"};
        String[] columns={"storeNum","business_name","province","city","district","address","longitude","latitude","telephone","categories","recommend","special","introduction","open_time","avg_price","storeCategoryId"};
        Render poirender = PoiRender.me(list).fileName("store.xls").headers(header).sheetName("store").columns(columns);
        render(poirender);
    }

    /**
     *批量导入门店
     */
    @Before(Tx.class)
    public void importStore(){
        shopId=getAttr("shopId");
        UploadFile uploadFile = getFile("storeFile");
        File filExcel = new File(JFinal.me().getServletContext().getRealPath("upload")+"/"+uploadFile.getFileName());//默认文件路径
        ExcelReader excelReader=new ExcelReader();//new 一个对象
        try {
            InputStream is = new FileInputStream(filExcel);
            Map<Integer, List> map = excelReader.readExcelContent(is);

            for(int i=1;i<=map.size();i++){//多少行
                JSONObject jo=null;
                BrandStore brandStore=new BrandStore();
                List<String> list=map.get(i);
                for(int j=0;j<list.size();j++){//取出每行的数据

                    if(StrKit.isBlank(list.get(2))||StrKit.isBlank(list.get(3))||StrKit.isBlank(list.get(4))||StrKit.isBlank(list.get(5))){//校验省市区或者地址不允许为空
                        renderJson(Msg.fail("导入失败,第"+(i+1)+"行省市区或者详细地址不允许为空!",""));
                        return;
                    }else if(StrKit.isBlank(list.get(8))){
                        renderJson(Msg.fail("导入失败,第"+(i+1)+"行电话不允许为空!",""));
                        return;
                    }else if(StrKit.isBlank(list.get(1))){
                        renderJson(Msg.fail("导入失败,第"+(i+1)+"行门店名称不允许为空!",""));
                        return;
                    }
                    //如果经度或者维度为空,则用腾讯地图根据省市区及其地址获取经纬度

                    String longitude="";
                    String latitude="";
                    if(j==6&&(StrKit.isBlank(list.get(6))|| StrKit.isBlank(list.get(7)))){
                        String address=list.get(2)+list.get(3)+list.get(4)+list.get(5);
                        //腾讯地图获取经纬度
                        /*String url="https://apis.map.qq.com/ws/geocoder/v1/?";
                        try {
                            String para=URLEncoder.encode("address="+address+"&key="+AConfig.p.get("QQMAP_KEY"),"utf-8");
                            String result=HttpKit.get(url+para);
                            System.out.println(result);
                            jo=new JSONObject(result);
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }*/
                        //百度地图获取经纬度
                        String url="https://api.map.baidu.com/geocoder/v2/?";
                        try {
                            address=URLEncoder.encode(address,"utf-8");
                            String para="address="+address+"&output=json&ak="+ AConfig.p.get("BAIDU_KEY")+"&ret_coordtype=gcj02ll";
                            String result=HttpKit.get(url+para);
                            jo=new JSONObject(result);
                            if(jo.get("status").toString().equals(1)){
                                renderJson(Msg.fail("导入失败,第"+(i+1)+"行地址错误!",""));
                            }
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }

                    }
                    if(j==0){
                        String storeNum=list.get(j);
                        if(StrKit.isBlank(storeNum)){//若门店编号为空,则自动生成5位门店编号
                            storeNum=SerialNumberUtil.buildStoreNum();
                        }else{//若门店编号不为空,验证门店编号是否存在
                            BrandStore currtStore=BrandStore.dao.getByStoreNumAndShopId(list.get(0),shopId);
                            if(currtStore!=null){
                                renderJson(Msg.fail("导入失败,第"+(i+1)+"行门店编号已存在!",""));
                                return;
                            }
                        }
                        brandStore.set("storeNum",storeNum);
                    }else if(j==1){//门店名称
                        String business_name=list.get(j);
                        brandStore.set("business_name",business_name);
                    }else if(j==2){//省
                        String province=list.get(j);
                        brandStore.set("province",province);
                    }else if(j==3){//市
                        String  city=list.get(j);
                        brandStore.set("city",city);
                    }else if(j==4){//区
                        String  district=list.get(j);
                        brandStore.set("district",district);
                    }else if(j==5){//详细地址
                        String  address=list.get(j);
                        brandStore.set("address",address);
                    }else if(j==6){//经度
                        longitude=list.get(j);
                        if(StrKit.isBlank(longitude)){
                            longitude=jo.getJSONObject("result").getJSONObject("location").get("lng").toString();
                        }
                        brandStore.set("longitude",longitude);
                    }else if(j==7){//维度
                        latitude=list.get(j);
                        //System.out.println("jo============"+jo);
                        if(StrKit.isBlank(latitude)){
                            latitude=jo.getJSONObject("result").getJSONObject("location").get("lat").toString();
                        }
                        brandStore.set("latitude",latitude);
                    }else if(j==8){//电话
                        String telephone=list.get(j).toString();
                        //BigDecimal telephone=new BigDecimal(list.get(j));
                        //DecimalFormat df=new DecimalFormat("#");//科学计数法转换为字符串
                        brandStore.set("telephone",telephone);
                    }else if(j==9){//类目
                        String categories=list.get(j);
                        if(categories.contains("，")){
                            renderJson(Msg.fail("导入失败,第"+(i+1)+"行门店类目请用英文逗号!",""));
                            return;
                        }
                        if(StrKit.isBlank(categories)){
                            categories=Member.dao.findById(shopId).getStr("categories");
                            if(StrKit.isBlank(categories)){
                                renderJson(Msg.fail("导入失败,第"+(i+1)+"行门店类目不允许为空!",""));
                                return;
                            }
                        }
                        brandStore.set("categories",categories);
                    }else if(j==10){//推荐品
                        String recommend=list.get(j);
                        brandStore.set("recommend",recommend);
                    }else if(j==11){//特色服务
                        String special=list.get(j);
                        brandStore.set("special",special);
                    }else if(j==12){//商户简介
                        String introduction=list.get(j);
                        brandStore.set("introduction",introduction);
                    }else if(j==13){//营业时间
                        String open_time=list.get(j);
                        brandStore.set("open_time",open_time);
                    }else if(j==14){//人均价格
                        String avg_price=list.get(j);
                        if(StrKit.isBlank(avg_price)){
                            avg_price=null;
                        }
                        brandStore.set("avg_price",avg_price);
                    }else if(j==15){
                        String storeCategoryId="";
                        String storeCategoryName=list.get(j);
                        if(StrKit.isBlank(storeCategoryName)){
                            storeCategoryId=null;
                        }else{
                            BrandStoreCategory bsc=BrandStoreCategory.dao.getByName(shopId,storeCategoryName);
                            if(bsc!=null){
                                storeCategoryId=bsc.getId();
                            }else{
                                BrandStoreCategory addbsc=new BrandStoreCategory();
                                String id=StrKit.getRandomUUID();
                                addbsc.set("id",id);
                                addbsc.set("name",storeCategoryName);
                                addbsc.set("shopId",shopId);
                                addbsc.set("createDate", new Date()).save();
                                storeCategoryId=id;
                            }
                        }
                        brandStore.set("storeCategoryId",storeCategoryId);

                    }

                }
                brandStore.set("id", CommonUtil.getUUID());
                brandStore.set("shopId", shopId);
                brandStore.set("createDate", new Date());
                brandStore.save();
                //BrandStore
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        filExcel.delete();


        renderJson(Msg.SUCCESS);
    }

    public static void main(String[] args) {
        /*String url="https://api.map.baidu.com/geocoder/v2/?";
        String address="";
        try {
            address=URLEncoder.encode("tttttrrr22eeee","utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        String para="address="+address+"&output=json&ak="+AConfig.p.get("BAIDU_KEY")+"&ret_coordtype=gcj02ll";
        String result=HttpKit.get(url+para);
        System.out.println(result);

        String url1="https://apis.map.qq.com/ws/geocoder/v1/?";
        try {
            String para1=URLEncoder.encode("address=江苏省苏州市工业园区星湖街328号&key="+AConfig.p.get("QQMAP_KEY"),"utf-8");
            String result1=HttpKit.get(url1+para1);
            System.out.println(result1);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }*/
        String str="111，22222";
        System.out.println(str.contains("，"));


    }


    /**
     * 门店同步到微信
     */
    public void pushToWeiXin(){
        shopId=getAttr("shopId");
        String id=getPara("id");
        BrandStore bs=BrandStore.dao.findById(id);
        if(bs.getInt("status")==1){
            renderJson(Ret.fail("info","该门店审核中,请勿重复推送!"));
            return;
        }
        //String loginMemberId = getSessionAttr(Member.LOGIN_MEMBER_ID_SESSION_NAME);//获取当前登录用户
        Member member=Member.dao.findById(shopId);
        String business_name=member.getStr("brandName");
        if(StrKit.isBlank(business_name)){
            renderJson(Ret.fail("info","门店名称(品牌商名称)不允许为空!"));
            return;
        }
        String errmsg= BrandStoreService.bss.pushToWeiXin(bs,shopId,business_name);
        if("ok".equals(errmsg)){
            renderJson(Ret.ok("info","推送成功!"));
        }else{
            renderJson(Ret.fail("info","推送失败!"));
        }
    }

    /**
     * 开启门店
     */
    public void open(){
        String id=getPara("id");
        BrandStore bs=BrandStore.dao.findById(id);
        bs.set("storeStatus",1).update();
        renderJson(Ret.ok("info","操作成功!"));
    }

    /**
     * 关闭门店(微信公众号上的门店删除)
     */
    public void close(){
        shopId=getAttr("shopId");
        String id=getPara("id");
        BrandStore bs=BrandStore.dao.findById(id);
        if(bs.getInt("status")==1){
            renderJson(Ret.fail("info","该门店审核中,无法关闭!"));
            return;
        }
        if(bs.getInt("status")==2 || bs.getInt("status")==3){//审核通过或审核不通过
            String poi_id=bs.getStr("poiId");
            String access_token=CommonUtil.getAccessToken(shopId);
            String deleteUrl="https://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token="+access_token;
            HashMap map=new HashMap();
            map.put("poi_id",poi_id);
            HttpKit.post(deleteUrl,JsonKit.toJson(map));
        }

        bs.set("status",0);
        bs.set("storeStatus",0).update();
        renderJson(Ret.ok("info","操作成功!"));
    }

}
